package com.dkm.controller;


import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.dkm.util.FileUtils;
import com.dkm.util.ResultUtil;

@RestController
@RequestMapping("/img")
public class ImgUploadController {
	@Value("${web.upload-path}")
    private String path;

    /**
     * @param file 要上传的文件
     * @return
     */
    //@PassToken
    @PostMapping("/upload")
    public ResultUtil upload(@RequestParam("file") MultipartFile file) {

        if (FileUtils.upload(file, path, file.getOriginalFilename())) {
            // 上传成功，给出页面提示
            return new ResultUtil(0, file.getOriginalFilename(),null);
        } else {
        	return new ResultUtil(1,"上传失败",null );
        }
    }
}
